package com.sailing.xjpb.orm.dialect;

import org.hibernate.dialect.PostgreSQL95Dialect;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
import org.hibernate.type.descriptor.sql.VarcharTypeDescriptor;

import java.sql.Types;

/**
 * PG方言配置
 */
public class SailingPGDialect extends PostgreSQL95Dialect {

    public SailingPGDialect() {
        super();
        registerHibernateType(Types.OTHER, "string");
        registerHibernateType(Types.ARRAY, "string-array");
    }

    @Override
    public SqlTypeDescriptor remapSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor) {
        switch (sqlTypeDescriptor.getSqlType()) {
            case Types.CLOB:
            case Types.BLOB:
                // 1111应该是pgsql的json
            case Types.OTHER:
                return VarcharTypeDescriptor.INSTANCE;
            default:
                return super.remapSqlTypeDescriptor(sqlTypeDescriptor);
        }
    }

}
